package com.cly.controller;

import com.cly.base.controller.BaseController;
import com.cly.entity.Subject;
import com.cly.result.JsonRequest;
import com.cly.service.ISubjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 科目表业务层实现
 *
 * @author 春风能解释
 * <p>
 * 2024-06-06
 */
@RestController
@RequestMapping("/subject")
@Tag(name = "科目表控制类", description = "科目表操作访问接口")
public class SubjectController extends BaseController<ISubjectService, Subject> {

    /**
     * 根据条件查询科目表信息
     *
     * @param subject 条件
     * @return JSON
     */
    @GetMapping("/listAll")
    @Operation(summary = "根据条件查询科目表信息")
    public JsonRequest<List<Subject>> lookSubject(
            @Parameter(description = "科目表条件")
            Subject subject) {
        return baseService.lookAllSubject(subject);
    }

    /**
     * 根据条件查询科目表信息
     *
     * @param current 页码
     * @param size    页长
     * @param subject 条件
     * @return JSON
     */
    @GetMapping("/list")
    @Operation(summary = "根据条件查询科目表信息")
    public JsonRequest<List<Subject>> lookSubject(
            @Parameter(description = "页码", required = true)
            @RequestParam Integer current,
            @Parameter(description = "页长", required = true)
            @RequestParam Integer size,
            @Parameter(description = "科目表条件")
            Subject subject) {
        return baseService.lookSubject(current, size, subject);
    }

    /**
     * 新增一条科目表信息
     *
     * @param subject 科目表信息
     * @return JSON
     */
    @PostMapping
    @Operation(summary = "新增一条科目表信息")
    public JsonRequest<Integer> addOneSubject(
            @Parameter(description = "科目表信息", required = true)
            @RequestBody Subject subject) {
        return baseService.addOneSubject(subject);
    }

    /**
     * 修改一条科目表信息
     *
     * @param subject 科目表信息
     * @return JSON
     */
    @PutMapping
    @Operation(summary = "修改一条科目表信息")
    public JsonRequest<Integer> updateOneSubject(
            @Parameter(description = "科目表信息", required = true)
            @RequestBody Subject subject) {
        return baseService.updateOneSubject(subject);
    }

    /**
     * 批量删除科目表信息
     *
     * @param ids 科目表id列表
     * @return JSON
     */
    @DeleteMapping
    @Operation(summary = "批量删除科目表信息")
    public JsonRequest<Integer> deleteSubjects(
            @Parameter(description = "科目表id列表", required = true)
            @RequestBody List<Long> ids) {
        return baseService.deleteSubjects(ids);
    }

    /**
     * 根据ID查询科目信息并转换为Map
     *
     * @param ids id
     * @return JSON
     */
    @PostMapping("/ids")
    @Operation(summary = "根据ID查询科目信息并转换为Map")
    public JsonRequest<Map<Long, Subject>> lookSubjectMap(
            @Parameter(description = "科目id列表", required = true)
            @RequestBody List<Long> ids) {
        return baseService.lookSubjectMap(ids);
    }

}